define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    $("#c-must_goods").data("params", function () {//点击商品下拉框就会触发这个，获取分类ID，并且赋值，这个时候请求的地址就是 zhl/message/selectpage1?id=获取的分类ID
        var id = $("#c-id").val();
        var mustgoods = $("#c-must_goods").val();
        return {custom: {id: id,must_goods:mustgoods}} ;
    });
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'boxfl/index' + location.search,
                    add_url: 'boxfl/add',
                    edit_url: 'boxfl/edit',
                    del_url: 'boxfl/del',
                    multi_url: 'boxfl/multi',
                    import_url: 'boxfl/import',
                    table: 'boxfl',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'catename', title: __('Catename'),searchList: {
                            ordinary: __("Ordinary"),
                            demo: __("Demo"),
                            fortune: __("Fortune"),
                            collecting: __("Collecting"),
                        }, formatter: Table.api.formatter.flag,},
                        {field: 'box_thumb_image', title: __('Box_thumb_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'box_name', title: __('Box_name'), operate: 'LIKE'},
                        {field: 'box_label', title: __('Box_label'), operate: 'LIKE'},
                        {field: 'lable', title: __('Lablename'),searchList: {
                            hot: __("Hot"),
                            phone: __("Phone"),
                            live: __("Live"),
                            play: __("Play"),
                        }, formatter: Table.api.formatter.flag,},
                        {field: 'probability_gj', title: __('Probability_gj'), operate:'BETWEEN'},
                        {field: 'probability_xy', title: __('Probability_xy'), operate:'BETWEEN'},
                        {field: 'probability_ss', title: __('Probability_ss'), operate:'BETWEEN'},
                        {field: 'probability_cs', title: __('Probability_cs'), operate:'BETWEEN'},
                        {field: 'must_goods', title: __('Must_goods'), operate:false, formatter: Table.api.formatter.label},
                        {field: 'boxswitch', title: __('Boxswitch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'single_switch', title: __('Single_switch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'new_switch', title: __('New_switch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-catename").change(function (){
               let val = $("#c-catename").val()
                if (val === 'fortune' || val =='collecting') {
                    $('.prize-status').removeClass('hide')
                    $("#c-prize-id").attr('data-rule','required');
                } else {
                    $('.prize-status').addClass('hide');
                   
                }
            });
            // let val = $("#c-catename").val()
            // if (val === 'fortune' || val =='collecting') {
            //     $('.prize-status').removeClass('hide')
            //       $("#c-prize-id").attr('data-rule','required');
            // } else {
            //     $('.prize-status').addClass('hide');
            //      $("#c-prize-id").remove.attr('data-rule','required');
            // }
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-catename").change(function (){
               let val = $("#c-catename").val()
                if (val === 'fortune' || val =='collecting') {
                    $('.prize-status').removeClass('hide')
                    $("#c-prize-id").attr('data-rule','required');
                } else {
                    $('.prize-status').addClass('hide');
                   
                }
            });
            let val = $("#c-catename").val()
            console.info(val);
            if (val === 'fortune' || val =='collecting') {
                $('.prize-status').removeClass('hide')
                $("#c-prize-id").attr('data-rule','required');
            } else {
                $('.prize-status').addClass('hide');
                 
            }
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;
});
